const user = {
	namespaced: true,
  state: {
		roleKey: uni.getStorageSync('RH-Role-KEY') || 'waterRepair',
		userObj: {}, //用户信息
  },
  mutations: {
		SETROLEKEY(state, key){
			state.roleKey = key
			console.log(state.roleKey, 666)
		},
		SETUSEROBJ(state, obj){
			state.userObj = obj
		}
	},
  actions: {
		setRoleKey({commit}, obj){
			console.log(obj, 9999)
			return new Promise((resolve, reject) => {
				uni.setStorage({
					key: 'RH-NICK-NAME',
					data: obj['apiNickName'] || '接口未返回用户名称'
				})
				uni.setStorage({
					key: 'RH-PHONE-NUMBER',
					data: obj['apiPhonenumber'] || '接口未返回手机号'
				})
				uni.setStorage({
					key: 'RH-Role-KEY',
					data: obj['roleKey'],
					success: () => {
						commit('SETROLEKEY', obj.roleKey)
					}
				})
				// 居民情况
				if(obj.roleKey == 'resident'){
					uni.setStorage({
						key: 'RH-USER-OBJ',
						data: JSON.stringify(obj['apiLiveUser']),
						success: () => {
							commit('SETUSEROBJ', obj.apiLiveUser)
						}
					})
				}else{ //非居民情况
					
				}
			})
		},
	},
  getters: {
		roleKey: state => state.roleKey
	}
}
export default user